<?php
class Home extends Controller{
	function Home(){
		parent::Controller();
		$this->load->helper(array('url','function','common','js'));
 		$this->load->model('Mhome');
		$this->load->library('pagination');
	}
	
	//展示一个导航页面，仅此而已
	function index(){
		load_view('index');
	}
	
	//创建自增加的ID
	function new_id(){
		$id=$this->Mhome->last_id()+1;
		return $id;
	}
	
	//保存信息入库，这里实际上就是新建一个发送的表单
	function new_info(){
		$new_id=self::new_id();
		$form = array('othername','qu','serv','prof','role','maid','gameid','gamepass');
		$values =get_data($form);
		/*上传相关config*/
		$config['upload_path'] = './uploads/card/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '100';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
		$this->load->library('upload', $config);
		if($this->input->post("sub_info")){
			//上传判断
			if (!$this->upload->do_upload("passcard")){
				$values['passcard']="nocard";
				alert_go("图片上传有问题！",'modify/'.$new_id);
			}else{
				$uploaddata=$this->upload->data();
				$values['passcard']=$uploaddata['file_name'];
			}
			$values['id'] =$new_id;
			$values['creattime'] = date('Y-m-d H:i:s');
			$updata=$this->upload->data();
			$query=$this->Mhome->insert_info($values);
			redirecter("插入成功！","home/index",$delay=3);		
		}
		$data['id']=$new_id;
		load_view('new',$data);
	}


	//修改相关信息更新
	function modify(){
		$id=$this->uri->segment(3);
		$data['list_info']=$this->Mhome->list_info($id);
		load_view("modify",$data);
	}



	function update_info(){
		$new_id=$this->uri->segment(3);
		$form = array('othername','qu','serv','prof','role','maid','gameid','gamepass');
		$values =get_data($form);
		/*上传相关config*/
		$config['upload_path'] = './uploads/card/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '100';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
		$this->load->library('upload', $config);

		if($this->input->post("sub_info")){
			//上传判断
			if (!$this->upload->do_upload("passcard")){
				$values['passcard']="nocard";
				redirecter("图片上传有问题！","home/modify/$new_id",$delay=1);		
			}else{
				$uploaddata=$this->upload->data();
				$values['passcard']=$uploaddata['file_name'];
				$values['id'] =$new_id;
				$values['creattime'] = date('Y-m-d H:i:s');
				$query=$this->Mhome->update_modify($values,$new_id);
				if($query){
					redirecter("更新成功！","home/index",$delay=3);		
				}
			}
		}
		$data['list_info']=$this->Mhome->list_info($new_id);
		load_view("modify",$data);
	}

	//订单概要显示
	function list_tips(){
		$id=$this->uri->segment(3);
        $base_url=base_url().'index.php/home/list_tips/'.$id;
		$qtotal=$this->Mhome->list_tips_total();
		$total=$qtotal[0]->total;
		$start=$this->uri->segment(4,0);
		$data['page_html'] = pagebar($base_url,$total,15);
		$data['list_tips']=$this->Mhome->list_tips($start,15);
		load_view('list',$data);
	}

	function search(){
		load_view("search");
	}

	//根据流水号来查询订单
	function search_by_id(){
		$rs=$this->input->post("sub_search");
		if(isset($rs)){
			$id=$this->input->post("search_id");
			if($id<self::new_id()){
				$data['list_info']=$this->Mhome->list_info($id);
				load_view("modify",$data);

			}else{
					redirecter("没有你要查找的订单,返回继续！","home/search",$delay=1);		
			}
		}
	}

	function change_RN(){
		$id=$this->uri->segment(3);
		$this->Mhome->chang_rubbish($id);
		redirecter("订单已经进入垃圾箱！","home/list_tips",$delay=1);	
	}

	function change_NR(){
		$id=$this->uri->segment(3);
		$this->Mhome->chang_nomal($id);
		redirecter("订单已经恢复正常","home/list_tips",$delay=1);	
	}











}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */